package ca.jsbr.as2js_lib.display.canvas.bitmap.imageFilter 
{
	import ca.jsbr.as2js_lib.display.canvas.bitmap.BitmapData;
	import js.element.canvas.CanvasRenderingContext2D;
	import js.ImageData;
	/**
	 * ...
	 * @author jsbr [me@jsbr.ca]
	 */
	public class Flip implements IFilter
	{
		private var _horizontal:Boolean;
		private var _vertical:Boolean;
		
		public function Flip(horizontal:Boolean=true,vertical:Boolean=false) 
		{
			_vertical = vertical;
			_horizontal = horizontal;
			
		}
		
		
		public function render(bitmapData:BitmapData) 
		{
			var ret:ImageData = bitmapData.context.createImageData(bitmapData.width, bitmapData.height);
			var data = bitmapData.imageData.data;
			var len:int = data.length
			var index = 0;
			for (var i:int = 0; i < len; i += 4)
			{
				//trace("R:",data[i+0],"G:",data[i+1],"B",data[i+2],"data",data[i+3],"length:");
				if (_vertical && _horizontal)
				{
					index = len-i;
					ret.data[index] = data[i];
					ret.data[index+1] = data[i + 1];
					ret.data[index+2] = data[i + 2];
					ret.data[index+3] = data[i + 3];
				}
				else if (_horizontal)
				{
					i *= 0.25;
					index = (i / bitmapData.width) >> 0;
					index *= bitmapData.width;
					index += bitmapData.width-(i % bitmapData.width);
					i *= 4;
					index *= 4;
					ret.data[index] = data[i];
					ret.data[index+1] = data[i + 1];
					ret.data[index+2] = data[i + 2];
					ret.data[index+3] = data[i + 3];
				}
				else if (_vertical)
				{
					
				}
			}
			
			return ret
		}

		
		
	}

}